package com.pingguopifa.interceptor;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.pingguopifa.utils.ActionCategoryLayout;
import com.pingguopifa.utils.DatedFileAppender;

public class LoggerService {

	private String logPrefix;
	private String auditDir;
	private String loggerName;
	private Logger logger;
	private DatedFileAppender appender;
	private static final String LOG_SUFFIX = ".log";
	public static final char AUDIT_TRAIL_DELIMITER = '|';
	
	public void constructLogger() {
		this.logger = Logger.getLogger(loggerName);
		appender = new DatedFileAppender(auditDir, logPrefix, LOG_SUFFIX);
		appender.setEncoding("utf-8");
		appender.setLayout(new ActionCategoryLayout());
		logger.addAppender(appender);
		logger.setLevel(Level.INFO);
		logger.setAdditivity(false);
	}
	
	public void info(String message){
		logger.info(message);
	}

	public void destoryResource() {
		appender.close();
		logger.removeAllAppenders();
	}

	public void setLogPrefix(String logPrefix) {
		this.logPrefix = logPrefix;
	}
	public void setAuditDir(String auditDir) {
		this.auditDir = auditDir;
	}
	
	public void setLoggerName(String loggerName) {
		this.loggerName = loggerName;
	}
}
